define(['store'], function (store) {
    'use strict';
    function ctrl($scope, $state,$ionicLoading, CommonService, WebService) {

        function init() {
           var signInfo = store.get('SignInfo');
            $scope.contracter = {
                mobile: signInfo != null ? signInfo.mobile : '',
                name: signInfo != null ? signInfo.name : '',
                relationship: signInfo != null ? signInfo.relationship : {}
            };
            $scope.formEvents = {
                submit: function () {
                      //创业板转签申请提交
                    var params = {second_contact_name:$scope.contracter.name,
                                  second_contact_mobile:$scope.contracter.mobile,
                                  second_contact_relative:$scope.contracter.relationship.val};
                    $ionicLoading.show();
                    WebService.saveSecondInfo(params).then(function (data) {
                        $ionicLoading.hide();
                        if(data.error_no != '0'){
                            if(data.error_no=='-8'){
                                CommonService.showAlert({message:"您好，创业板转签请在交易日09:00-16:00进行办理。"});
                            }else{
                                CommonService.showAlert({message:data.error_info});
                            }
                        }else{
                            CommonService.showComplete('../view/template/signtemplate.html', '返回首页', 'tab.account-index');
                        }
                    },function(){
                        CommonService.showAlert({message:"转签申请失败"})
                    });
                },
                goRelationship: function () {
                    store.set('SignInfo', $scope.contracter);
                    $state.go('tab.account-relationship');
                }
            }

        }

        $scope.$on('$ionicView.beforeEnter', function () {
            init();
        });
    }

    ctrl.$inject = ['$scope', '$state','$ionicLoading', 'CommonService', 'WebService'];
    return ctrl;
});